package com.yanqu.road.entity.activity.silkroad.entity;

public class SilkRoadLine {
    private double k;
    private double b;

    public SilkRoadLine(){}
    public SilkRoadLine(double k , double b){
        this.k = k;
        this.b = b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public void setK(double k) {
        this.k = k;
    }

    public double getB() {
        return b;
    }

    public double getK() {
        return k;
    }
    public void showLine(){
        System.out.println(" y = "+k+"x"+"+"+b);
    }


    public boolean isPointOnLine(SilkRoadCircle p){
        if((k* p.getX() + b)==p.getY()){
            System.out.println("该点在直线上！");
            return true;
        }
        else
        {
            System.out.println("该点不在直线上");
            return false;
        }
    }
    public void leftMove(double l){
        b = k * l + b;
    }
    public void rightMove(double l){
        b = k * (-l) + b;
    }
    public void upMove(double l){
        b = b + l;
    }
    public void downMove(double l){
        b = b - l;
    }

    //圆心到线的距离
    public double getPointDistance(SilkRoadCircle p){
        return Math.abs(k * p.getX() - p.getY() + b) / Math.sqrt(Math.pow(k,2) + 1);
    }

}

